<template>
	<view>
		<uni-section title="科目" type="line">
			<uni-card :is-shadow="true" is-full>
				<text class="uni-h6">{{pName}}</text>
			</uni-card>
		</uni-section>
		<uni-section title="事件标题" type="line">
		  	<uni-card :is-shadow="true" is-full>
		  		<text class="uni-h6">{{item.title}}</text>
		  	</uni-card>
		</uni-section>
		<uni-section title="事件内容" type="line">
			<webEdit v-model="item.content" ids="content" :modelValue="item.content" ></webEdit>
		</uni-section>
		<uni-section title="备注" type="line">
			<uni-card :is-shadow="true" is-full>
				<textarea  v-model="item.describes"  :value="item.describes"/>
			</uni-card>
		</uni-section>
			<uni-card :is-shadow="true" is-full>
				<button type="primary" @click="submit()" :disabled="sbBtn">确认完成</button>
			</uni-card>
	</view>	
</template>

<script>
import config from "@/config.js";
import { getSubject} from "@/api/plan/subject";
import { updateContent,getContent,addContent} from "@/api/plan/content";
import { updateReview} from "@/api/plan/review";
export default {
	data() {
		return {
			sbBtn:false,
			value: 0,
			pName:'',
			item: {},
		}
	},
	onLoad(option) {
		this.item = JSON.parse(option.item);			
		this.item.content = this.item.content.replace(/\/dev-api/g,config.baseUrl);
		this.item.content = this.item.content.replace(/\<img/g,'<img style="width:100%;height:auto;display:block"');
		this.getSubjectList();
	},	
	onBackPress() {
		uni.$emit('refreshData',{msg:'返回'})
	},
	methods: {
		/** 查询科目列表  新增今日学习内容时使用 */
		getSubjectList() {
			getSubject(this.item.subjectId).then(response => {
				this.pName = response.data.pName;
			});
		},
		submit() {
			this.sbBtn = true;
			uni.showToast({
				title: `gooood!`
			})
			let target = config.baseUrl;
			let regex = new RegExp(target, 'g');
			this.item.content = this.item.content.replace(regex, '/dev-api');
			this.item.content = this.item.content.replace(/style="width:100%;height:auto;display:block" /g, '');
			//flag : 1  content   2  review
			if(this.item.flag === 1){
				this.item.studyStatus = '1';
				updateContent(this.item);
			}else{
				this.item.reviewStatus = '1';
				let review = {
					id:this.item.rid,
					reviewStatus:this.item.reviewStatus
				}
				updateReview(this.item);			
			}					
			setTimeout(function(){
				uni.navigateBack({
					delta: 1, // 返回层数，2则上上页
					success() {
						uni.$emit('refreshTip',{msg:'Tip'})
					}
				})
			},2000)
		},
	}
}
</script>

<style>
	.example {
		padding: 15px;
		background-color: #fff;
	}
	.content{
		.uni-section-content{
			padding: 0 20px;
		}
	}
</style>